<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script>
    function page(n,s){
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchFormDict").submit();
        return false;
    }
    $(document).ready(function(){
        initTree();
        $("#ztreePatient").height($("body").height()*0.6);

    });
    /**
     * 病人列表查询
     * */
    function patList(){
        $("#searchForm").submit();
    }
    /*
     双击病人列表加载工作页面
     */
    function loadDoctorWork(visitId,patientId,div){
        $("#patientIdVal").val(patientId);
        $("#visitIdVal").val(visitId);
        $("#patientSearchDiv").hide();
        $(".conter-card").css("width","100%");
        $(".conter").css("width","100%");
//        $("#patientListDiv").attr("class","col-lg-3");
        $("#doctorWorkDiv").show();
        $("#infoCheckId").show();
        $("#newFloatDiv").hide();
        $("#newRightDiv").hide();
        $(div).parent().find(".selected").attr("class","conter-card");
        $(div).attr("class","conter-card selected");
        $(div).parent().find("div:first").before($(div));
        $(".wrapper-img").scrollTop(0);
        $(".conter-card-bottom").hide();
        $("#doctorUlId li:first a:first").click();
    }
    /**
    *返回病人列表
     */
    function returnDoctorWork(){
        $("#patientSearchDiv").show();
        $(".conter-card").css("width","18.5%");
        $(".conter").css("width","90%");
//        $("#patientListDiv").attr("class","col-lg-12");
        $("#doctorWorkDiv").hide();
        $("#infoCheckId").hide();
        $("#newFloatDiv").show();
        $("#newRightDiv").show();
        $(".conter-card-bottom").show();
    }
    /**
     * 全部信息切换
     * */
    function showAllInfo(type){
        if(type=='1'){
            $(".conter-card-bottom").hide();
        }else{
            $(".conter-card-bottom").show();
        }
    }
    function newLayerLoad(url,val,title){
        var patientId=$("#patientIdVal").val();
        var visitId=$("#visitIdVal").val();
        var ctx=url;
        if(val==1||val=='1'){
           // url = "${ctx}/doctor/medicalRecord/form";
        }else if(val==2||val=='2'){
            ctx = url+"?patientId="+patientId+"&patVisitId="+visitId;
        }else if(val==3||val=='3'){
            ctx = url+"?patientId="+patientId+"&patVisitId="+visitId;
        }else if(val==4||val=='4'){
           // url = "${ctx}/doctor/medicalRecord/form";
        }
        layer.open({
            type: 2,
            title: title,
            skin: 'layui-layer-rim', //样式类名
            shadeClose: true,
            shade: 0.5,
            area: ['62%', '80%'],
            content:ctx
        });

    }
    /**
     * 切换医生操作界面
     * @param url
     * @param li
     */
    function loadDoctorDiv(url,li){
        var patientId=$("#patientIdVal").val();
        var visitId=$("#visitIdVal").val();
        url=url+"?patientId="+patientId+"&visitId="+visitId;
        loadDiv('rigthDoctorCenterDiv',url)
        $("#doctorUlId li").removeClass("active");
        $(li).parent().addClass("active");
    }

    function initTree(){
        var setting = {data:{simpleData:{enable:true,idKey:"id",pIdKey:"pId",rootPId:'0'}},
            callback:{onClick:function(event, treeId, treeNode){
                var id = treeNode.pId == '0' ? '' :treeNode.pId;
                if(!treeNode.isParent){
                    $("#deptNameId").val(treeNode.id);//显示值
                    $("#deptName").val(treeNode.name);//显示值
                    patList();
                }else{
                    toastr.error("请选择最下级科室");
                }

                //加载选择科室的数据
            }
            }
        };
        $.getJSON("${ctx}/sys/orgDept/treeData?role=1",function(data){
            $.fn.zTree.init($("#ztreePatient"), setting, data).expandAll(true);
        });

    }

    function selectedUser(id,name,visitNo,type,varStatus){
        if(type =='1'){
            $("a[name='doctorInCharge']").eq(varStatus).html(name+'<span class="caret"></span>');
        } else if(type =='2'){
            $("a[name='upperDoctor']").eq(varStatus).html(name+'<span class="caret"></span>');
        } else {
            $("a[name='directorDoctor']").eq(varStatus).html(name+'<span class="caret"></span>');
        }
        $.ajax({
            type: "POST",
            url: '${ctx}/doctor/patVisit/updateUser?doctorInCharge='+id+'&visitNo='+visitNo+'&type='+type,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    toastr.success(data.data);
                } else if(data.code == 'info'){
                } else {
                    toastr.error(data.data);
                }
            }
        })
    }
</script>
<!-- content wrapper -->
<div class="content-wrap">
    <div class="wrapper wrapper-img">
        <div class="app">
            <section class="layout">
                <div class="col-lg-12" id="patientListDiv">
                    <div class="col-sm-12 icheck" id="infoCheckId" style="display: none">
                            <div class="m5 pull-left">
                                <input tabindex="7" type="radio" onchange="showAllInfo('1')" id="minimal-radio-1" name="minimal-radio" checked>
                                <label for="minimal-radio-1">基本信息</label>
                            </div>
                            <div class="m5 pull-left">
                                <input tabindex="8" type="radio" id="minimal-radio-2" onchange="showAllInfo('2')" name="minimal-radio">
                                <label for="minimal-radio-2">全部信息</label>
                            </div>
                         <span class="layui-layer-setwin" id="doctorWorkEnlarge">
                        <a class="layui-layer-ico layui-layer-max" href="javascript:;" onclick="returnDoctorWork()"></a>
                    </span>
                    </div>
                        <div class="nav nav-tabs" id="patientSearchDiv">
                        <form:form id="searchForm" modelAttribute="patVisit" onsubmit="return loadDivForm('mainCenterDiv','searchForm','${ctx}/doctor/patVisit/index');" method="post"  class="form-inline" style="padding-top: 10px" >
                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
                            <div class="col-lg-12">
                                <div class="col-sm-3">
                                    <div class="col-sm-12 icheck">
                                        <div class="m5 pull-left">
                                            <form:radiobutton path="inFlag" onclick="patList();" value="0"></form:radiobutton>
                                            <label for="minimal-radio-1">在院：</label>
                                        </div>
                                        <div class="m5 pull-left">
                                            <form:radiobutton path="inFlag" onclick="patList();" value="1"></form:radiobutton>
                                            <label for="minimal-radio-2">已出院：</label>
                                        </div>
                                        <div class="m5 pull-left">
                                            <form:radiobutton path="inFlag" onclick="patList();" value="2"></form:radiobutton>
                                            <label for="minimal-radio-2">归档：</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <label class="control-label">出院时间：</label>
                                    <form:input path="startDate"  id="date"  class="form-control Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
                                    至<form:input path="endDate"  class="form-control Wdate"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
                                </div>

                            </div>
                            <div class="col-lg-12">
                                <div class="col-lg-3 mt5">
                                    <label class="control-label col-sm-4">权限科室：</label>
                                    <div class="input-group mb15 col-sm-8" id="deptDivId">
                                        <input id="deptName" name="deptStayedEt.deptName" value="${fns:getUser().orgDept.deptName}"  class="form-control"/>
                                        <input id="deptNameId" name="deptStayedEt.id" value="${fns:getUser().orgDept.id}"  type="hidden" />
                                        <div class="input-group-btn">
                                            <button id="deptBtn" type="button"  class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1" aria-expanded="false">
                                                <span class="caret"></span>
                                            </button>
                                            <div  class="dropdown-menu pull-right" role="menu" >
                                                <div class="ztree" id="ztreePatient" style="overflow: auto">

                                                </div>
                                            </div>
                                        </div>
                                        <!-- /btn-group -->
                                    </div>
                                </div>
                                <div class="col-lg-3 mt5">
                                    <label class="control-label">病人姓名：</label>
                                    <form:input  path="patVisitIndex.name"   class="form-control" />
                                </div>
                                <div class="col-lg-1 mt5">
                                    <button class="btn-sm btn btn-primary" type="submit"><span class="fa fa-search"></span>查询</button>
                                </div>
                            </div>
                        </form:form>
                    </div>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="conter">
                                <c:forEach items="${page.list}" var="pat" varStatus="varStatus">
                                    <div class="conter-card" ondblclick="loadDoctorWork('${pat.id}','${pat.patientId}',this)">
                                        <div class="conter-card-top">
                                            <div class="img">
                                                <c:choose>
                                                    <c:when test="${pat.patVisitIndex.sex=='1'}">
                                                        <img src="${ctxStatic}/images/nv.png"/>
                                                    </c:when>
                                                    <c:otherwise><img src="${ctxStatic}/images/nan.png"/></c:otherwise>
                                                </c:choose>

                                            </div>
                                            <div class="miss">
                                                <div class="height-23">
                                                    <span class="badge bg-primary pull-right">${pat.visitNo}</span>
                                                </div>

                                                <div class="miss-top"><span style="font-weight:bold;margin-left: 20px">${pat.patVisitIndex.name}</span><span class="badge pull-right bg-success">${pat.patVisitIndex.age}</span></div>
                                            </div>
                                        </div>
                                        <div class="conter-card-bottom">
                                            <ul  type="none">
                                                <li><span class="title">床号：</span><span class="text">${pat.bedNo}</span></li>
                                                <li><span class="title">病情：</span>
                                                    <div class="text">
                                                        <c:choose>
                                                            <c:when test="${pat.situationType=='1'}">
                                                                 <span class="label label-danger">
                                                                    危
                                                                </span>
                                                            </c:when>
                                                            <c:when test="${pat.situationType=='2'}">
                                                                 <span class="label label-warning">
                                                                    重
                                                                </span>
                                                            </c:when>
                                                            <c:when test="${pat.situationType=='3'}">
                                                                 <span class="label label-success">
                                                                    一般
                                                                </span>
                                                            </c:when>
                                                        </c:choose>
                                                    </div>
                                                </li>
                                                <li><span class="title">住院天数：</span ><span class="text">${pat.zhuyuanTians}</span></li>
                                                <li><span class="title">预交金：</span><span class="text">${pat.prepayments}</span></li>
                                                <li><span class="title">产生费用：</span><span class="text">
                                                    <c:choose>
                                                        <c:when test="${pat.price == null || pat.price == ''}">
                                                            0
                                                        </c:when>
                                                        <c:otherwise>${pat.price}</c:otherwise>
                                                    </c:choose>
                                                </span></li>
                                                <li><span class="title">管床医师：</span><span class="text">
                                                    <div class="btn-group">
                                                        <a href="#" id="doctorInCharge" name="doctorInCharge" data-toggle="dropdown">
                                                            ${pat.doctorInCharge} <span class="caret"></span>
                                                        </a>
                                                        <ul class="dropdown-menu" role="menu">
                                                            <c:forEach items="${users}" var="u">
                                                            <li><input type="hidden" value="${u.id}"><a href="#" onclick="selectedUser('${u.id}','${u.name}','${pat.visitNo}','1','${varStatus.index}')">${u.name}</a></li>
                                                            </c:forEach>
                                                        </ul>
                                                    </div>
                                                </span></li>
                                                <li><span class="title">上级医师：</span><span class="text">
                                                    <div class="btn-group">
                                                        <a href="#" id="upperDoctor" name="upperDoctor" data-toggle="dropdown">
                                                                ${pat.upperDoctorEt.name} <span class="caret"></span>
                                                        </a>
                                                        <ul class="dropdown-menu" role="menu">
                                                            <c:forEach items="${users}" var="u">
                                                                <li><input type="hidden" value="${u.id}"><a href="#" onclick="selectedUser('${u.id}','${u.name}','${pat.visitNo}','2','${varStatus.index}')">${u.name}</a></li>
                                                            </c:forEach>
                                                        </ul>
                                                    </div>
                                                </span></li>




                                                </span></li>
                                                <li><span class="title">主治医师：</span><span class="text">
                                                    <div class="btn-group">
                                                        <a href="#" id="directorDoctor" name="directorDoctor" data-toggle="dropdown">
                                                                ${pat.upperDoctorEt.name} <span class="caret"></span>
                                                        </a>
                                                        <ul class="dropdown-menu" role="menu">
                                                            <c:forEach items="${users}" var="u">
                                                                <li><input type="hidden" value="${u.id}"><a href="#" onclick="selectedUser('${u.id}','${u.name}','${pat.visitNo}','3','${varStatus.index}')">${u.name}</a></li>
                                                            </c:forEach>
                                                        </ul>
                                                    </div>
                                                </span></li>
                                            </ul>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                            <div class="float" id="newFloatDiv">
                                <button class="float-btn btn-new" onclick="newLayerLoad('${ctx}/doctor/medicalRecord/turnInIndexDept',1,'移入科室')">移入科室</button>
                                <button class="float-btn btn-in" onclick="newLayerLoad('${ctx}/doctor/medicalRecord/cancelTurnInDept',2,'取消移入')">取消移入</button>
                                <button class="float-btn btn-out" onclick="newLayerLoad('${ctx}/doctor/medicalRecord/turnOutDept',3,'移出科室')">移出科室</button>
                                <button class="float-btn btn-cet" onclick="newLayerLoad('${ctx}/doctor/medicalRecord/cancelTurnOutDept',4,'取消移出')">取消移出</button>
                                <%--<button class="float-btn btn-cet" onclick="newLayerLoad(5)">刷新病历列表</button>--%>
                            </div>
                            <div class="right" id="newRightDiv">
                                <div class="bottom-btn right-bottom-new"></div>
                                <div class="bottom-btn right-bottom-in"></div>
                                <div class="bottom-btn right-bottom-out"></div>
                                <div class="bottom-btn right-bottom-cet"></div>
                            </div>
                            <div class="pagination">${page}</div>
                        </div>
                    </section>
                </div>
                    <input type="hidden" id="patientIdVal">
                    <input type="hidden" id="visitIdVal">
                <section class="main-content col-lg-9" style="display: none" id="doctorWorkDiv">
                    <div class="content-wrap">
                        <div class="wrapper">
                            <ul class="nav nav-tabs" id="doctorUlId">
                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/orders/orders/index',this)">医嘱信息</a>
                                </li>
                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/doctor/hisDiagnosis/index',this)">诊断</a>
                                </li>
                                <li class="active">
                                    <a href="#" onclick="loadDoctorDiv('/a/doctor/patVisit/findById',this)">病人基本信息</a>
                                </li>
                                <%--<li>--%>
                                    <%--<a href="#" onclick="loadDoctorDiv('/a/doctor/clinicRecord/index',this)">病人病历</a>--%>
                                <%--</li>--%>

                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/doctor/prescriptionApply/index',this)">处方申请</a>
                                </li>
                                <li id="examApplyLi">
                                    <a href="#" onclick="loadDoctorDiv('/a/exam/examApply/index',this)">检查申请</a>
                                </li>
                                <li id="labApplyLi">
                                    <a href="#" onclick="loadDoctorDiv('/a/lab/labApply/index',this)">检验申请</a>
                                </li>

                                <%--<li>--%>
                                    <%--<a href="#" onclick="loadDoctorDiv('/a/treat/outpTreatRec/index',this)">处置治疗</a>--%>
                                <%--</li>--%>

                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/blood/bloodApply/index',this)">用血申请</a>
                                </li>
                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/operation/operationApply/index',this)">手术申请</a>
                                </li>
                                <li>
                                    <a href="#" onclick="loadDoctorDiv('/a/doctor/preDischgedPats/index',this)">出院通知单</a>
                                </li>
                                <li>
                                    <a href="#" onclick="loadDoctorDiv('${ctx}/finance/inpBillDetail/refundList',this)">退药申请</a>
                                    </li>
                            </ul>
                            <div class="row" id="rigthDoctorCenterDiv"  style="height:90%">

                            </div>
                        </div>
                    </div>
                </section>
            </section>
        </div>
    </div>
</div>